<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>注册页面</h1>
    <form action="/register" method="post" id="form1">
        账号：<input type="text" name="username" /><br />
        密码：<input type="password" name="pwd" /><br />
        确认密码：<input type="password" id="repwd" /><br />
        <button>提交</button>
    </form>
    <script>
        // 修改提交方式 - 阻止默认表单提交
        let form1 = document.querySelector('#form1');
        let pwd = document.getElementsByName('pwd')[0];
        let username = document.getElementsByName('username')[0];
        let repwd = document.querySelector('#repwd');

        form1.onsubmit = function(e){

            if(username.value.length<6){
                alert('用户名长度不得小于6位，请重新输入');
                e.preventDefault();
                return;
            }

            if(pwd.value.length<6){
                alert('密码长度不得小于6位，请重新输入');
                e.preventDefault();
                return;
            }

            if(!repwd.value.length){
                alert('请输入确认密码');
                e.preventDefault();
                return;
            }


            // alert('1');
            if(pwd.value !== repwd.value){
                alert('您输入的密码不一致，请重新输入');
                e.preventDefault();
                // return;
            }
        }

    </script>
</body>
</html>